package com.swl.controller;

import com.swl.pojo.Choose;
import com.swl.pojo.Topic;
import com.swl.pojo.User;
import com.swl.service.ChooseService;
import com.swl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/choose")
public class ChooseController {
    @Autowired
    private ChooseService chooseService;
    @RequestMapping("/insertChoose")
    @ResponseBody
    public Integer insertChoose(@RequestParam("Topic.tid") int tid,String answerA,String answerB,String answerC,String answerD){
        System.out.println("insertChoose执行了");
        Choose choose1=new Choose();
        choose1.setAnswer(answerA);
        choose1.setTopic(new Topic(tid));

        Choose choose2=new Choose();
        choose2.setAnswer(answerB);
        choose2.setTopic(new Topic(tid));

        Choose choose3=new Choose();
        choose3.setAnswer(answerC);
        choose3.setTopic(new Topic(tid));

        Choose choose4=new Choose();
        choose4.setAnswer(answerD);
        choose4.setTopic(new Topic(tid));

        chooseService.insertChoose(choose1);
        chooseService.insertChoose(choose2);
        chooseService.insertChoose(choose3);
        chooseService.insertChoose(choose4);
        return 1;
    }

    @RequestMapping("/selectChooseByTid")
    @ResponseBody
    public List<Choose> selectChooseByTid(@RequestParam("tid") int tid){
        System.out.println("selectChooseByTid执行了");
        return chooseService.selectChooseByTid(tid);
    }


    @RequestMapping("/selectAnswerByChooseId")
    @ResponseBody
    public Choose selectAnswerByChooseId(@RequestParam("chooseId") int chooseId){
        System.out.println(chooseId);
        Choose answer = chooseService.selectAnswerByChooseId(chooseId);
        System.out.println(answer);
        return answer;
    }
}
